﻿@using Entidades.Sistema.Base
@using System.Collections.ObjectModel;

@{
    Html.EnableClientValidation();
    Html.EnableUnobtrusiveJavaScript();

    var grid = Html.DevExpress().GridView(
        settings =>
        {
            settings.Name = "gvEditing";
            settings.KeyFieldName = "IdCargo";
            settings.CallbackRouteValues = new { Controller = "Cargo", Action = "EditCargosPartial" };

            settings.Columns.Add(column =>
            {
                column.Caption = "#";
                column.SetDataItemTemplateContent(c =>
                {
                    ViewContext.Writer.Write(
                        Html.ActionLink("Editar", "EditCargosUpdatePartial", new { IdCargo = DataBinder.Eval(c.DataItem, "IdCargo") }) + "&nbsp;" +
                        Html.ActionLink("Eliminar", "EditCargosDeletePartial", new { IdCargo = DataBinder.Eval(c.DataItem, "IdCargo") },
                            new { onclick = "return confirm('Realmente quiere elimnar el Cargo?')" })
                    );
                });
                column.SetHeaderTemplateContent(c =>
                {
                    ViewContext.Writer.Write(
                        Html.ActionLink("Nuevo", "EditCargosUpdatePartial", new { IdCargo = -1 }).ToHtmlString()
                        //Html.ActionLink("Nuevo", "Create", new { IdCargo = -1 }).ToHtmlString()
                    );
                });
                column.Settings.AllowDragDrop = DefaultBoolean.False;
                column.Settings.AllowSort = DefaultBoolean.False;
                column.Width = 70;
            });
            
            
            
            settings.SettingsBehavior.ConfirmDelete = true;
            settings.SettingsPopup.EditForm.Width = 600;
            settings.SettingsPopup.EditForm.HorizontalAlign = PopupHorizontalAlign.Center;
            settings.SettingsPopup.EditForm.VerticalAlign = PopupVerticalAlign.WindowCenter;
            settings.SettingsPager.FirstPageButton.Visible = true;
            settings.SettingsPager.LastPageButton.Visible = true;
            settings.SettingsPager.PageSizeItemSettings.Visible = true;
            settings.SettingsPager.PageSizeItemSettings.Items = new string[] { "10", "20", "50" };
            
            
            settings.Settings.ShowFilterRow = true;
            settings.Settings.ShowFilterRowMenu = true;
            settings.CommandColumn.Visible = true;
            settings.CommandColumn.ShowClearFilterButton = true;
            
            settings.Width = System.Web.UI.WebControls.Unit.Percentage(100);

            settings.Columns.Add("IdCargo");
            settings.Columns.Add("Nombre");
            settings.Columns.Add("Descripcion");
            settings.Columns.Add(columnCheck =>
            {
                columnCheck.FieldName = "HabilitadoProduccion";
                columnCheck.ColumnType = MVCxGridViewColumnType.CheckBox;

                var checkBoxProperties = columnCheck.PropertiesEdit as CheckBoxProperties;
                checkBoxProperties.ValueUnchecked = null;
                columnCheck.Width = 50;
            });
          
             
        });
        
              

    if (ViewData["EditError"] != null){
        grid.SetEditErrorText((string)ViewData["EditError"]);
    }
}

@grid.Bind(Model).GetHtml()









